<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set value="<%=request.getContextPath()%>" var="ctx"></c:set>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title>订单中心</title>
    <meta name="viewport" content="width=device-width,user-scalable=no, initial-scale=1">
    <meta name="format-detection" content="telephone=yes">
    <meta name="msapplication-tap-highlight" content="no">
      <link href="${ctx}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- Data Tables -->
    <link href="${ctx}/css/plugins/dataTables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="${ctx}/css/animate.css" rel="stylesheet">
    <link href="${ctx}/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${ctx}/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
        <!-- 全局js -->
    <script src="${ctx}/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx}/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- Data Tables -->
    <script src="${ctx}/js/plugins/dataTables/jquery.dataTables.js"></script>
    <script src="${ctx}/js/plugins/dataTables/dataTables.bootstrap.js"></script>
    <script src="${ctx}/js/plugins/layer/layer.min.js"></script>
    <script src="${ctx}/js/plugins/layer/laydate/laydate.js"></script>
    <!-- 自定义js -->
    <script src="${ctx}/js/content.js?v=1.0.0"></script>
    <script src="${ctx}/js/plugins/sweetalert/sweetalert.min.js"></script>
    <style>
    	#container1{
    		position:absolute;
    		width:500px;
    		border:1px solid red;
    		top:0px;
    		margin:0px 35%;
    	}
    	table{
    		text-align:center;
    	}
    </style>
</head>
<body>
<div class="modal inmodal in" id="add_modal" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">添加物流单号</h2>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="logisticsForm" method="POST">
						<div class="form-group">
							<label class="col-lg-3 control-label">物流单号：</label>
							<div class="col-lg-8">
								<input type="text" class="form-control" name="logisticsNumber" id="logisticsNumber"
									maxlength="50">
									<input type="hidden" class="form-control" name="id" id="orderId"
									maxlength="20">
							</div>
							<p id="errMsg"></p>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
					<button type="button" class="btn btn-primary" onclick ="save()" data-flg="0">确认</button>
				</div>
			</div>
		</div>
	</div>
<div class="modal inmodal in" id="sendGift_modal" tabindex="-1"
		role="dialog" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content animated fadeIn">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">
						<span aria-hidden="true">×</span><span class="sr-only">Close</span>
					</button>
					<h2 class="modal-title">订单详情</h2>
				</div>
				<div class="modal-body">
					<h5>商品列表</h5>
						<table id="gifts" border="1">
							
						</table>
					<h5>收货信息</h5>
					<p>
						收货人：<span id="name_"></span>
					</p>
					<p>
						收货人地址：<span id="addr_"></span>
					</p>
					<p>
						联系方式：<span id="mobile_"></span>
					</p>
					<h5>配送</h5>
					<p>
						物流公司：<span id="logistics_name_"></span>
					<p>
					<p>
						物流单号：<span id="logistics_number_"></span>
					<p>
					<h5 id="remark_info" >备注信息</h5>
					<p id="remark" style="display: none;">
						备注：<span id="remark_"></span>
					</p>
				</div>
			</div>
		</div>
	</div>
 <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox">
                    <div class="ibox-title">
                        <div class="row">
                           <div class="col-sm-3">
                                <h3>订单中心</h3>
                           </div>
                        </div>
                    </div>
                    <div class="ibox-content">
<!--                         <div id="progressBar" class="sk-spinner sk-spinner-wave" > -->
<!--                             <div class="sk-rect1"></div> -->
<!--                             <div class="sk-rect2"></div> -->
<!--                             <div class="sk-rect3"></div> -->
<!--                             <div class="sk-rect4"></div> -->
<!--                             <div class="sk-rect5"></div> -->
<!--                         </div> -->
                        <table class="table table-striped table-bordered table-hover dataTables-example text-center">
                            <thead>
                                <tr>
                                    <th class="text-center">订单号</th>
                                    <th class="text-center">购买用户</th>
                                    <th class="text-center">价格</th>
                                    <th class="text-center">下单日期</th>
                                    <th class="text-center">订单状态</th>
                                    <th class="text-center">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                            </tbody>
    				 </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script src="${ctx}/js/util.js"></script>
<script>
var sending = false;

var queryIndex = 1;
var table = null;
var index_ = 1;
$(document).ready(function(){
	var href = location.href;
	var length = href.length;
	var index = href.charAt(length-1);
	table = $('.dataTables-example').DataTable({
		"bPaginate" : true,//翻页功能
		"bSort" : false,//排序功能
		"aoColumns" : [
										{
											"sClass" : "center",
											"mRender" : function(
													data, type,
													full) {
													return full.id;
											}
										},
										{
											"sClass" : "center name",
											"mRender" : function(
													data, type,
													full) {
												return full.openid_;
											}
										},
										{
											"sClass" : "center value penma",
											"mRender" : function(
													data, type,
													full) {
												return full.price_;
											}
										},
										{
											"sClass" : "center value daima",
											"mRender" : function(
													data, type,
													full) {
												return full.create_time_;
											}
										},
										{
											"sClass" : "center value state",
											"mRender" : function(
													data, type,
													full) {
												var text = "未支付";
												if(full.status_==1){
													text = "待发货";
												}else if(full.status_ == 4){
													text = "待收货";
												}else if(full.status_ == 2){
													text = "待评价";
												}else if(full.status_ == 3){
													text = "完成";
												}
												return text;
											}
										},
										{
											"sClass" : "center value",
											"mRender" : function(
													data, type,
													full) {	
												var btns =  "<button type='button' class='btn btn-primary'  onclick='detail(\""
													+ full.id
													+ "\");return false;' >查看详情</button>";
													if(full.status_ == 1){
														btns += "<button type='button' id = '"+full.id+"' class='btn btn-success'  onclick='send(\""
														+ full.id
														+ "\");return false;' >发货</button>";	
													}else if(full.status_ == 4){
															btns += "<button type='button' id = '"+full.id+"' class='btn btn-success'  onclick='send(\""
															+ full.id
															+ "\");return false;' >修改单号</button>";	
													}
													
												return btns;									
											}
										}
										]
	});
		sendReq("${ctx}/order/toAllOrder",{id:index},function(data){
			for(var i =0,len=data.length;i<len;i++){
				table.row.add(data[i]);
			}
 				table.draw();
		});
					});


	function detail(id) {
		sendReq("${ctx}/order/detail",{id:id},function(data){
			var obj = data;
			var $gift = $("#gifts");
			$("#gifts").html("<tr><th>商品名称</th><th>商品单价</th><th>商品数量</th></tr>");
			var gifts = data.gifts,len = gifts.length;
			for(var i=0;i<len;i++){
				var gift = gifts[i];
				var html = "<tr><td>"+gift.name_+"</td><td>"+gift.price_+"</td><td>"+gift.count_+"</td></tr>";
				$gift.append($(html));
			}
			$('#name_').text(obj.addr.name_);
			$('#addr_').text(obj.addr.addr_);
			$('#mobile_').text(obj.addr.mobile_);
			$('#logistics_name_').text(obj.logistics_name_);
			$('#logistics_number_').text(obj.logistics_number_);
			$('#remark_').text(obj.remark_);
			$('#sendGift_modal').modal();
			
		})
	}
	function send(id){
		$("#logisticsNumber").val("");
		$("#add_modal").modal();
		cccc = id;
	}
	var cccc = -1;
	function save(){
		var num = $("#logisticsNumber").val();
		sendReq("${ctx}/order/lognum",{id:cccc,num:num},function(data){
			$("#add_modal").modal('hide');
			var btn = $("#"+cccc);
			btn.text("修改单号");
			var p = btn.parent().parent();
			$(".state",p).text("待收货");
		});
	}
</script>
</html>
